﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cmsservice.Common
{
    public class StringTools
    {
        public static string TxtClear(string content)
        {
            string str = content.Replace("\f", "")
                                .Replace("\b", "")
                                .Replace("\t", "");
            return str;
        }

        public static string TextToHtml(string txt)
        {
            txt = txt.Replace(" ", "&nbsp;").Replace("　", "&nbsp;&nbsp;").Replace("\r\n", "<br />").Replace("\n", "<br />");
            return txt;
        }

        public static string GetIp()
        {
            string ip = System.Web.HttpContext.Current.Request.Headers["X-Forwarded-For"];
            if (string.IsNullOrEmpty(ip))
            {
                ip = System.Web.HttpContext.Current.Request.UserHostAddress;
            }
            return ip;
        }

        public static bool CheckIp()
        {
            string ip = GetIp();
            if (ip.StartsWith("172") || ip.StartsWith("192") || ip == "127.0.0.1")
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
